package com.senlingspace.web.controller.headquarters;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageInfo;
import com.senlingspace.system.domain.SlkjOrder;
import com.senlingspace.system.domain.vo.SlkjCopyrightVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.senlingspace.common.annotation.Log;
import com.senlingspace.common.core.controller.BaseController;
import com.senlingspace.common.core.domain.AjaxResult;
import com.senlingspace.common.enums.BusinessType;
import com.senlingspace.system.domain.SlkjCopyright;
import com.senlingspace.system.service.ISlkjCopyrightService;
import com.senlingspace.common.utils.poi.ExcelUtil;
import com.senlingspace.common.core.page.TableDataInfo;

/**
 * 版权方列表Controller
 *
 * @author SenlingSpace
 * @date 2024-07-02
 */
@RestController
@RequestMapping("/system/copyright")
public class SlkjCopyrightController extends BaseController {
    @Autowired
    private ISlkjCopyrightService slkjCopyrightService;

    /**
     * 查询版权方列表列表
     */
    @PreAuthorize("@ss.hasPermi('system:copyright:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlkjCopyright slkjCopyright) {
        List<SlkjCopyright> list = slkjCopyrightService.selectSlkjCopyrightList(slkjCopyright);
        return getDataTable(list);
    }

    /**
     * 导出版权方列表列表
     */
    @PreAuthorize("@ss.hasPermi('system:copyright:export')")
    @Log(title = "版权方列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlkjCopyright slkjCopyright) {
        List<SlkjCopyright> list = slkjCopyrightService.selectSlkjCopyrightList(slkjCopyright);
        ExcelUtil<SlkjCopyright> util = new ExcelUtil<SlkjCopyright>(SlkjCopyright.class);
        util.exportExcel(response, list, "版权方列表数据");
    }

    /**
     * 获取版权方列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:copyright:query')")
    @GetMapping(value = "/{copyrightId}")
    public AjaxResult getInfo(@PathVariable("copyrightId") Long copyrightId) {
        return success(slkjCopyrightService.selectSlkjCopyrightByCopyrightId(copyrightId));
    }

    /**
     * 新增版权方列表
     */
    @PreAuthorize("@ss.hasPermi('system:copyright:add')")
    @Log(title = "版权方列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlkjCopyright slkjCopyright) {
        slkjCopyright.setCreateBy(super.getUserId() + "");
        return toAjax(slkjCopyrightService.insertSlkjCopyright(slkjCopyright));
    }

    /**
     * 修改版权方列表
     */
    @PreAuthorize("@ss.hasPermi('system:copyright:edit')")
    @Log(title = "版权方列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlkjCopyright slkjCopyright) {
        slkjCopyright.setUpdateBy(super.getUserId() + "");
        return toAjax(slkjCopyrightService.updateSlkjCopyright(slkjCopyright));
    }

    /**
     * 删除版权方列表
     */
    @PreAuthorize("@ss.hasPermi('system:copyright:remove')")
    @Log(title = "版权方列表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{copyrightIds}")
    public AjaxResult remove(@PathVariable Long[] copyrightIds) {
        return slkjCopyrightService.deleteSlkjCopyrightByCopyrightIds(copyrightIds);
    }


    /**
     * 版权方下拉列表
     *
     * @param copyrightNumber
     * @param companyName
     * @return
     */
    @GetMapping("/copyrightSelected")
    public AjaxResult copyrightSelected(@RequestParam(required = false) String copyrightNumber,
                                        @RequestParam(required = false) String companyName) {
        SlkjCopyright copyright = new SlkjCopyright();
        copyright.setCopyrightNumber(copyrightNumber);
        copyright.setCompanyName(companyName);
        copyright.setStatus(0);
        List<SlkjCopyright> list = slkjCopyrightService.copyrightSelected(copyright);
        return AjaxResult.success(list);
    }


    /**
     * 版权方日分账明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:copyright:copyrightDetail')")
    @GetMapping("/copyrightDetail")
    public TableDataInfo copyrightDetail(Date startTime,Date endTime ,Long shopId,String projectName,String copyrightName) {
        PageInfo<SlkjCopyrightVo> list = slkjCopyrightService.copyrightDetail(startTime,endTime,shopId,projectName,copyrightName);
        return getDataTable(list);
    }

    /**
     * 版权方日分账明细列表导出
     */
    @PreAuthorize("@ss.hasPermi('system:copyright:exportCopyrightDetail')")
    @PostMapping("/exportCopyrightDetail")
    public void exportCopyrightDetail(HttpServletResponse response, Date startTime,Date endTime ,Long shopId,String projectName) {
        startPage();
        List<SlkjCopyrightVo> list = slkjCopyrightService.exportCopyrightDetail(startTime,endTime,shopId,projectName,false);
        ExcelUtil<SlkjCopyrightVo> util = new ExcelUtil<SlkjCopyrightVo>(SlkjCopyrightVo.class);
        util.exportExcel(response, list, "版权方日分账明细列表数据");
    }

    /**
     * 版权方分账汇总表
     */
    @PreAuthorize("@ss.hasPermi('system:copyright:copyrightSummary')")
    @GetMapping("/copyrightSummary")
    public TableDataInfo copyrightSummary(Date startTime,Date endTime ,Long shopId) {
        startPage();
        PageInfo<SlkjCopyrightVo> list = slkjCopyrightService.copyrightSummary(startTime,endTime,shopId);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('system:copyright:exportCopyrightSummary')")
    @PostMapping("/exportCopyrightSummary")
    public void exportCopyrightSummary(HttpServletResponse response, Date startTime,Date endTime ,Long shopId) {
        startPage();
        List<SlkjCopyrightVo> list = slkjCopyrightService.exportCopyrightSummary(startTime,endTime,shopId);
        ExcelUtil<SlkjCopyrightVo> util = new ExcelUtil<SlkjCopyrightVo>(SlkjCopyrightVo.class);
        util.exportExcel(response, list, "版权方分账汇总表数据");
    }

    /**
     * 版权方累计收益趋势图（累计）
     */
    @GetMapping("/copyrightTrend")
    public TableDataInfo copyrightTrend(Date startTime,Date endTime,String projectName,String mobile) {
        startPage();
        List<SlkjCopyrightVo> list = slkjCopyrightService.copyrightTrend(startTime,endTime,projectName,mobile);
        return getDataTable(list);
    }

    /**
     * 版权方累计收益趋势图（每日）
     */
    @GetMapping("/copyrightTrendDay")
    public TableDataInfo copyrightTrendDay(Date startTime,Date endTime,String projectName,String mobile) {
        startPage();
        List<SlkjCopyrightVo> list = slkjCopyrightService.copyrightTrendDay(startTime,endTime,projectName,mobile);
        return getDataTable(list);
    }

    /**
     * 版权方累计收益趋势图（列表）
     */
    @GetMapping("/copyrightTrendList")
    public TableDataInfo copyrightTrendList(Date startTime,Date endTime, String projectName, String mobile) {
        startPage();
        List<SlkjCopyrightVo> list = slkjCopyrightService.copyrightTrendList(startTime,endTime,projectName,mobile);
        return getDataTable(list);
    }
}
